package com.klikmee.sms.chat.web.usecases;

import java.util.ArrayList;
import java.util.List;

import org.json.JSONException;
import com.dotexe.webframework.core.ClientApplication;
import com.dotexe.webframework.core.datasources.CollectionDataSource;
import com.dotexe.webframework.core.triggers.Trigger;
import com.klikmee.sms.chat.web.dao.BulkGroupDAO;
import com.klikmee.sms.chat.web.util.SpringBeansLookup;
import com.klikmee.sms.services.chat.model.BulkGroup;

public class BulkGroupListForm extends ClientApplication {

	private CollectionDataSource dsBulkGroups;
	private ArrayList<String> bcBulkGroups;
	
	private BulkGroupDAO groupDAO;
	private List<BulkGroup> groups;

	// override
	@Override
	public void load() throws Exception {
		super.load();

		this.dsBulkGroups = new CollectionDataSource("dsBulkGroups");
		this.getDataSources().add(this.dsBulkGroups);

		this.bcBulkGroups = new ArrayList<String>();
		this.bcBulkGroups.add("GroupName");
		this.bcBulkGroups.add("GroupDescription");

		this.triggers.add(new Trigger(this, "btnCancelClick"));
		this.triggers.add(new Trigger(this, "gvBulkGroupsCellClick"));
		this.triggers.add(new Trigger(this, "gvBulkGroupsCellDoubleClick"));
	}

	@Override
	public void start() throws Exception {
		super.start();

		groupDAO = SpringBeansLookup.getBean(BulkGroupDAO.class);
		groups = groupDAO.selectAllActive();
		this.dsBulkGroups.setSource(groups);
		this.dsBulkGroups.bind(bcBulkGroups);
	}

	public void gvBulkGroupsCellClick() throws JSONException {

	}

	public void gvBulkGroupsCellDoubleClick() throws JSONException {

	}

	public void btnCancelClick() throws JSONException {
		this.hide();
	}
}
